<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="misc.Configurations"%>
<%@page import="org.apache.commons.fileupload.servlet.*"%>
<%@page import="controller.UploadController"%>
<%@page import="controller.UploadController.UploadError"%>
<%@page import="data.File"%>
<%@page import="data.AuthorizationSession"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title><%=Configurations.title%>Upload</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<h1>Upload a file</h1>
<%
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if(isMultipart)
{
    UploadController control = new UploadController();
    UploadController.UploadResponse respond = control.processUploadResquest(request);

    if(respond.status==UploadError.ok)
    {
           %>
           <div class="success">You have uploaded the '<%=respond.filename %>' file (<%=respond.filesize%>) successfully!</div><br/>
           Code to download: <b><%=respond.filecode%></b><br/>
           <%
    }
    else if(respond.status==UploadError.toobig)
    {
        %>
        <div class="error">Your file is rejected because its size exceeds the size limit (<%=File.convertToMB(Configurations.FileSizeLimit) %>).</div>
        <%
    }
    else if(respond.status==UploadError.empty)
    {
        %>
        <div class="error">You uploaded nothing.</div>
        <%
    }
    else
    {
        %>
        <div class="error">The server encounters an unknown error. :-(</div>
        <%
    }
}
%>
<form enctype="multipart/form-data" action="Upload.jsp" method="post">
    <table border="0">
        <tr>
          <td>File</td><td><input type="file" size="40" name="filepath"/></td>
        </tr>
        <tr>
          <td colspan="2" align="right"><input type="submit" value="Upload"/></td>
        </tr>
    </table>
</form>
<%
if(AuthorizationSession.checkAuthorizationToken(request,null,false))
{
%>
<br/>
<div align="right">
<form>
    <input type="button" value="Back to management" onclick="javascript:window.location = 'ManageFiles.jsp';"/>
</form>
</div>
<%
}
else
{
%>
<small>Note: Anonymous users can only upload files of up to <%=File.convertToMB(Configurations.FileSizeLimit) %> and keep for <%=Configurations.AvailableTime %> minutes.</small>
<%
}
%>
</body>
</html>